package org.sport.presenter;


import net.sf.json.JSONObject;
import org.sport.logic.Logic_Homepage;
import org.sport.model.jsonModel.Json_1_calorie;
import org.sport.model.jsonModel.Json_1_kilometre;
import org.sport.model.jsonModel.Json_1_walkNum;
import org.sport.model.jsonModel.Json_1_weight;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by zehong
 *
 * 主要用于对接首页面，即分析页面，返回步数，大卡，体重，公里等信息
 */


@Controller
public class Interface_Homepage {

    @Autowired
    Logic_Homepage logicForHomepage;



    /**
     * 功能：获取步数的历史数据
     * json参数：用户手机号码
     * 返回：步数的历史数据
     */
    @RequestMapping(value = "/1/walkNum", method = RequestMethod.POST)
    public void walkNum(@RequestBody Json_1_walkNum json_1_walkNum
            , HttpServletRequest request
            , HttpServletResponse response
    )
    {
        System.out.println("进入Interface-5-walkNum");
        json_1_walkNum = logicForHomepage.walkNum(json_1_walkNum);
        try {
            response.getWriter().print(JSONObject.fromObject(json_1_walkNum).toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    /**
     * 功能：获取大卡的历史数据
     * json参数：用户手机号码
     * 返回：大卡的历史数据
     */
    @RequestMapping(value = "/1/calorie", method = RequestMethod.POST)
    public void calorie(@RequestBody Json_1_calorie json_1_calorie
            , HttpServletRequest request
            , HttpServletResponse response
    )
    {
        System.out.println("进入Interface-5-calorie");
        json_1_calorie = logicForHomepage.calorie(json_1_calorie);
        try {
            response.getWriter().print(JSONObject.fromObject(json_1_calorie).toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }




    /**
     * 功能：获取体重的历史数据
     * json参数：用户手机号码
     * 返回：体重的历史数据
     */
    @RequestMapping(value = "/1/weight", method = RequestMethod.POST)
    public void weight(@RequestBody Json_1_weight json_1_weight
            , HttpServletRequest request
            , HttpServletResponse response
    )
    {
        System.out.println("进入Interface-5-weight");
        json_1_weight = logicForHomepage.weight(json_1_weight);
        try {
            response.getWriter().print(JSONObject.fromObject(json_1_weight).toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }




    /**
     * 功能：获取公里数的历史数据
     * json参数：用户手机号码
     * 返回：公里数的历史数据
     */
    @RequestMapping(value = "/1/kilometre", method = RequestMethod.POST)
    public void kilometre(@RequestBody Json_1_kilometre json_1_kilometre
            , HttpServletRequest request
            , HttpServletResponse response
    )
    {
        System.out.println("进入Interface-5-kilometre");
        json_1_kilometre = logicForHomepage.kilometre(json_1_kilometre);
        try {
            response.getWriter().print(JSONObject.fromObject(json_1_kilometre).toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }




}
